module top
(

    inout                   PAD_CDRX_L0P                ,
    inout                   PAD_CDRX_L0N                ,
    inout                   PAD_CDRX_L1P                ,
    inout                   PAD_CDRX_L1N                ,
    inout                   PAD_CDRX_L2P                ,
    inout                   PAD_CDRX_L2N                ,
    inout                   PAD_CDRX_L3P                ,
    inout                   PAD_CDRX_L3N                ,
    inout                   PAD_CDRX_L4P                ,
    inout                   PAD_CDRX_L4N                ,

    inout                   PAD_CDTX_L0P                ,
    inout                   PAD_CDTX_L0N                ,
    inout                   PAD_CDTX_L1P                ,
    inout                   PAD_CDTX_L1N                ,
    inout                   PAD_CDTX_L2P                ,
    inout                   PAD_CDTX_L2N                ,
    inout                   PAD_CDTX_L3P                ,
    inout                   PAD_CDTX_L3N                ,
    inout                   PAD_CDTX_L4P                ,
    inout                   PAD_CDTX_L4N                ,

    inout                   pad_rosc_cosc_sel           ,
    inout                   pad_dcdc_pg                 ,

    inout                   pad_rst_n                   ,
    inout                   pad_te                      ,
    inout                   pad_oled_en                 ,
    inout                   pad_swire                   ,
    inout                   pad_pwm                     ,

    inout                   pad_psram1_clk_p            ,
    inout                   pad_psram1_clk_n            ,
    inout                   pad_psram1_ce_n             ,
    inout                   pad_psram1_dm               ,
    inout                   pad_psram1_dqs              ,
    inout   [7:0]           pad_psram1_dq               ,

    inout                   pad_psram2_clk_p            ,
    inout                   pad_psram2_clk_n            ,
    inout                   pad_psram2_ce_n             ,
    inout                   pad_psram2_dm               ,
    inout                   pad_psram2_dqs              ,
    inout   [7:0]           pad_psram2_dq                

);

wire            apb_en      ;
wire            apb_wr      ;
wire [17:0]     apb_addr    ;
wire [31:0]     apb_wdata   ;

wire            mipi_rx_apb_clk     ;
wire            mipi_rx_apb_rst_n   ;
wire            mipi_rx_apb_sel     ;
wire [31:0]     mipi_rx_apb_rdata   ;

wire            vpre_apb_clk     ;
wire            vpre_apb_rst_n   ;
wire            vpre_apb_sel     ;
wire [31:0]     vpre_apb_rdata   ;

wire            memctrl_apb_clk     ;
wire            memctrl_apb_rst_n   ;
wire            memctrl_apb_sel     ;
wire [31:0]     memctrl_apb_rdata   ;

wire            vpost_apb_clk     ;
wire            vpost_apb_rst_n   ;
wire            vpost_apb_sel     ;
wire [31:0]     vpost_apb_rdata   ;

wire            mipi_tx_apb_clk     ;
wire            mipi_tx_apb_rst_n   ;
wire            mipi_tx_apb_sel     ;
wire [31:0]     mipi_tx_apb_rdata   ;

wire            system_ctrl_apb_clk     ;
wire            system_ctrl_apb_rst_n   ;
wire            system_ctrl_apb_sel     ;
wire [31:0]     system_ctrl_apb_rdata   ;

wire            vpre_vsync;
wire            vpre_hsync;
wire            vpre_de;
wire [29:0]     vpre_data0;
wire [29:0]     vpre_data1;

wire            sleep_out;
wire            display_on;
wire [15:0]     mem_startx;
wire [15:0]     mem_endx;
wire [15:0]     mem_starty;
wire [15:0]     mem_endy;
wire            mem_bp;
wire            mem_te;
wire            mem_interrupt;
wire            mem_vsync;
wire            mem_hsync;
wire            mem_de;
wire [29:0]     mem_data0;
wire [29:0]     mem_data1;



wire            chiprx_vid_vsync        ;
wire            chiprx_vid_hsync        ;
wire            chiprx_vid_vld          ;
wire [3:0]      chiprx_vid_vld_nvb      ;
wire            chiprx_vid_line_last    ;
wire            chiprx_vid_frame_last   ;
wire [63:0]     chiprx_vid_data         ;
wire [11:0]     chiprx_vid_hres         ;
wire [11:0]     chiprx_vid_vres         ;
wire [11:0]     chiprx_vid_hst          ;
wire [11:0]     chiprx_vid_hend         ;
wire [11:0]     chiprx_vid_vst          ;
wire [11:0]     chiprx_vid_vend         ;
wire [641:0]    chiprx_dsc_regs_cfg     ;
wire            chiprx_cmd2tx_vld       ;
wire            chiprx_cmd2tx_slpin     ;
wire            chiprx_cmd2tx_slpout    ;
wire            chiprx_cmd2tx_disoff    ;
wire            chiprx_cmd2tx_dison     ;
wire [15:0]     chiprx_cmd2tx_DBV_val   ;


mcu u6_mcu
(
    // Inputs
    .FCLK                               (apb_clk),
    .GLOBALRESETn                       (apb_rst_n),

    .SWCLKTCK                           (mcu_swclktck         ),
    .SWDITMS                            (mcu_swditms          ),
    .SWDO                               (mcu_swdo             ),
    .SWDOEN                             (mcu_swdoen           ),

    // Ports for Interface SIO
    .uart_1_SIO_sin                     (uart_1_SIO_sin     ),
    .uart_1_SIO_sout                    (uart_1_SIO_sout    ),
    .uart_0_SIO_sin                     (uart_0_SIO_sin     ),
    .uart_0_SIO_sout                    (uart_0_SIO_sout    ),
    // Ports for GPIO
    .gpio_ext_porta                     (gpio_ext_porta     ),
    .gpio_porta_dr                      (gpio_porta_dr      ),
    .gpio_porta_ddr                     (gpio_porta_ddr     ),
    // Ports for SPI M
    .spi_M_rxd                          (i_spi_M_rxd          ),
    .spi_M_sclk_out                     (o_spi_M_sclk_out     ),
    .spi_M_ss_0_n                       (o_spi_M_ss_0_n       ),
    .spi_M_txd                          (o_spi_M_txd          ),
    .spi_M_ssi_oe_n                     (o_spi_M_ssi_oe_n     ),
    // Ports for SPI S  
    .spi_S_sclk_in                      (i_spi_S_sclk_in      ),
    .spi_S_ss_in_n                      (i_spi_S_ss_in_n      ),
    .spi_S_rxd                          (i_spi_S_rxd          ),
    .spi_S_txd                          (o_spi_S_txd          ),
    .spi_S_ssi_oe_n                     (o_spi_S_ssi_oe_n     ),
    // Ports for SSI flash 
    .ssi_ssi_clk                        (flash_clk            ),
    .ssi_ssi_rst_n                      (flash_rst_n          ),
    .ssi_sclk_out                       (o_ssi_sclk_out       ),
    .ssi_ss_0_n                         (o_ssi_ss_0_n         ),
    .ssi_ssi_rxd                        (i_ssi_ssi_rxd        ),
    .ssi_ssi_txd                        (o_ssi_ssi_txd        ),
    .ssi_ssi_oe_n                       (o_ssi_ssi_oe_n       ),
    // Ports for i2c_M     
    .i2c_M_ic_clk_in_a                  (i2c_M_ic_clk_in_a  ),
    .i2c_M_ic_data_in_a                 (i2c_M_ic_data_in_a ),
    .i2c_M_ic_clk_oe                    (i2c_M_ic_clk_oe    ),
    .i2c_M_ic_data_oe                   (i2c_M_ic_data_oe   ),
    // Ports for i2c_S   
    .i2c_S_ic_clk_in_a                  (i2c_S_ic_clk_in_a  ),
    .i2c_S_ic_data_in_a                 (i2c_S_ic_data_in_a ),
    .i2c_S_ic_clk_oe                    (i2c_S_ic_clk_oe    ),
    .i2c_S_ic_data_oe                   (i2c_S_ic_data_oe   ),
    
    .apb_1_penable                      (apb_en             ),
    .apb_1_pwrite                       (apb_wr             ),
    .apb_1_paddr                        (apb_addr           ),
    .apb_1_pwdata                       (apb_wdata          ),
    
    .PCLK_CHIP_CTRL                     (system_ctrl_apb_clk        ),
    .PRESETn_CHIP_CTRL                  (system_ctrl_apb_rst_n      ),
    .apb_1_psel_s9                      (system_ctrl_apb_sel        ),
    .CHIP_CTRL_intr                     (1'b0 ),
    .CHIP_CTRL_prdata                   (system_ctrl_apb_rdata      ),
    .CHIP_CTRL_dma_tx_req               (1'b0 ),
    .CHIP_CTRL_dma_rx_req               (1'b0 ),
    .CHIP_CTRL_dma_rx_ack               (),
    .CHIP_CTRL_dma_tx_ack               (),


    .PCLK_CHIP_RX                       (mipi_rx_apb_clk),
    .PRESETn_CHIP_RX                    (mipi_rx_apb_rst_n),
    .apb_1_psel_s3                      (mipi_rx_apb_sel),
    .CHIP_RX_intr                       (1'b0 ),
    .CHIP_RX_prdata                     (mipi_rx_apb_rdata),
    .CHIP_RX_dma_tx_req                 (1'b0 ),
    .CHIP_RX_dma_rx_req                 (1'b0 ),
    .CHIP_RX_dma_rx_ack                 (),
    .CHIP_RX_dma_tx_ack                 (),
    
    .PCLK_CHIP_TX                       (mipi_tx_apb_clk),
    .PRESETn_CHIP_TX                    (mipi_tx_apb_rst_n),
    .apb_1_psel_s8                      (mipi_tx_apb_sel),
    .CHIP_TX_intr                       (1'b0 ),
    .CHIP_TX_prdata                     (mipi_tx_apb_rdata),
    .CHIP_TX_dma_tx_req                 (1'b0 ),
    .CHIP_TX_dma_rx_req                 (1'b0 ),
    .CHIP_TX_dma_rx_ack                 (),
    .CHIP_TX_dma_tx_ack                 (),

    .PCLK_CPA                           (),
    .PRESETn_CPA                        (),
    .apb_1_psel_s5                      (),
    .CPA_intr                           (1'b0 ),
    .CPA_prdata                         (32'h0),
    .CPA_dma_tx_req                     (1'b0 ),
    .CPA_dma_rx_req                     (1'b0 ),
    .CPA_dma_rx_ack                     (),
    .CPA_dma_tx_ack                     (),
    
    .PCLK_MEMC_PROC                     (memctrl_apb_clk),
    .PRESETn_MEMC_PROC                  (memctrl_apb_rst_n),
    .apb_1_psel_s6                      (memctrl_apb_sel),
    .MEMC_PROC_intr                     (1'b0 ),
    .MEMC_PROC_prdata                   (memctrl_apb_rdata),
    .MEMC_PROC_dma_tx_req               (1'b0 ),
    .MEMC_PROC_dma_rx_req               (1'b0 ),
    .MEMC_PROC_dma_rx_ack               (),
    .MEMC_PROC_dma_tx_ack               (),
    
    .PCLK_VPOST                         (vpost_apb_clk),
    .PRESETn_VPOST                      (vpost_apb_rst_n),
    .apb_1_psel_s7                      (vpost_apb_sel),
    .VPOST_intr                         (1'b0 ),
    .VPOST_prdata                       (vpost_apb_rdata),
    .VPOST_dma_tx_req                   (1'b0 ),
    .VPOST_dma_rx_req                   (1'b0 ),
    .VPOST_dma_rx_ack                   (),
    .VPOST_dma_tx_ack                   (),
    
    .PCLK_VPRE                          (vpre_apb_clk),
    .PRESETn_VPRE                       (vpre_apb_rst_n),
    .apb_1_psel_s4                      (vpre_apb_sel),
    .VPRE_intr                          (1'b0 ),
    .VPRE_prdata                        (vpre_apb_rdata),
    .VPRE_dma_tx_req                    (1'b0 ),
    .VPRE_dma_rx_req                    (1'b0 ),
    .VPRE_dma_rx_ack                    (),
    .VPRE_dma_tx_ack                    () 

);

endmodule

